//
//  SignalTableViewCell.m
//  Select
//
//  Created by dihuijun on 17/3/15.
//  Copyright © 2017年 Cycle. All rights reserved.
//

#import "SignalTableViewCell.h"

@implementation SignalTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}




/**  绘制分割线  */
-(void)drawRect:(CGRect)rect{
    CGContextRef  contextRef = UIGraphicsGetCurrentContext();
    ///表格颜色
    CGContextSetFillColorWithColor(contextRef, [UIColor whiteColor].CGColor);//颜色
    CGContextFillRect(contextRef, rect);
    ///分割线颜色
    CGContextSetStrokeColorWithColor(contextRef, ColorRGB(0xf7f7f7).CGColor);
    CGContextStrokeRect(contextRef, CGRectMake(0, rect.size.height-0.5, rect.size.width, 0.5));
}

/** 初始化 */
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        //创建子控件
        [self setupChild];
        
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}
/** 创建子控件 */
- (void)setupChild{
    //1.1 标题控件
    self.titleLabel                          = [UILabel new];
    self.titleLabel.textColor                = [UIColor darkTextColor];
    self.titleLabel.font                     = [UIFont systemFontOfSize:16.0];
    self.titleLabel.textAlignment            = NSTextAlignmentLeft;
    [self.contentView addSubview:self.titleLabel];
    //布局
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left).offset(15);
        make.top.mas_equalTo(self.contentView.mas_top);
        make.height.mas_equalTo(self.contentView.mas_height);
    }];
    
    
    //1.2 按钮控件
    self.selectIconButton                     = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.selectIconButton setImage:[UIImage imageNamed:@"table_UnSelect"] forState:UIControlStateNormal];
    [self.selectIconButton setImage:[UIImage imageNamed:@"table_Selected"] forState:UIControlStateSelected];
    //是否触摸按钮
    self.selectIconButton.userInteractionEnabled = NO;
    [self.contentView addSubview:self.selectIconButton];
    //布局
    [self.selectIconButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.titleLabel.mas_right).offset(10);
        make.right.mas_equalTo(self.contentView.mas_right).offset(-15);
        make.top.mas_equalTo(self.contentView.mas_top);
        make.height.mas_equalTo(self.contentView.mas_height);
        make.height.mas_equalTo(50);
    }];
    
    
    
}

#pragma mark --- 更新状态
- (void)updateCellWithState:(BOOL)select{
    
    self.selectIconButton.selected = select;
    
    _isSelected = select;
    
    
}

@end
